class Solution {
public:
    string compressString(string S) {
        size_t size = S.size();
        if(size <= 1) return S;
        string res;
        int cnt = 1;
        char ch = S[0];
        for(size_t i = 1; i < S.size(); ++i){
            if(ch == S[i]) ++cnt;
            else{
                res += ch + to_string(cnt);
                ch = S[i];
                cnt = 1;
            }
        }
        res += ch + to_string(cnt);
        if(size <= res.size()) return S;
        else return res;
    }
};